//
//  PKReadinglistTableViewController2.m
//  PianKe
//
//  Created by mingtao on 15/10/12.
//  Copyright (c) 2015年 mingtao. All rights reserved.
//

#import "PKReadinglistTableViewController2.h"
#import "PKRequestManager.h"
#import "PKRadingListModel.h"
#import "PKReadingTableViewCell.h"

#import "PKRequestManager.h"

@interface PKReadinglistTableViewController2 ()

@property(nonatomic,strong)NSMutableArray *arraylistview;


@end

@implementation PKReadinglistTableViewController2

-(NSMutableArray *)arraylistview
{
    if (_arraylistview == nil) {
        _arraylistview = [NSMutableArray arrayWithCapacity:0];
    }
    return _arraylistview;

}

-(void)request:(NSString *)strAll
{
    NSMutableDictionary *dictReading=[NSMutableDictionary dictionary];
    
    dictReading[@"typeid"] =self.strID;
    dictReading[@"deviceid"] = @"63A94D37-33F9-40FF-9EBB-481182338873";
    dictReading[@"client"] = @"1";
    dictReading[@"sort"] = strAll;
    [PKRequestManager requestWithType:POST urlString:@"http://api2.pianke.me/read/columns_detail" parDic:dictReading finish:^(NSData *data) {
        
        NSDictionary *dicData=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSArray *array=dicData[@"data"][@"list"];
        
        
        for (NSDictionary *keyDic in array) {
            
            PKRadingListModel *listModel=[[PKRadingListModel alloc]init];
            [listModel setValuesForKeysWithDictionary:keyDic];
            
            [self.arraylistview addObject:listModel];
            
        }
        
        [self.tableView reloadData];
        
        
    } error:^(NSError *error) {
        NSLog(@"PKReadingTableViewControllerCell 请求异常%@",error);
    }];
    

}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    
   // self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIHES, HHIHEI)];
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.rowHeight=140;
    
    [self.view addSubview:_manview];
    
    [self.tableView registerClass:[PKReadingTableViewCell class] forCellReuseIdentifier:@"PKReadingTableViewCell"];
    
    //请求数据
    [self request:@"addtime"];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return self.arraylistview.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    PKReadingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PKReadingTableViewCell" forIndexPath:indexPath];
    
    // Configure the cell...
    cell.listPP = _arraylistview[indexPath.row];
    
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
